package org.common.controller;


import cn.hutool.core.lang.tree.Tree;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.common.model.entity.Role;
import org.common.response.ResultData;
import org.common.service.IMenuService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-04-21
 */
@Slf4j
@CrossOrigin
@RestController
@RequiredArgsConstructor
@RequestMapping("/menu")
public class MenuController {

    private final IMenuService menuService;

    /**
     * 查询所有菜单数据
     * @param
     * @return
     */
    @GetMapping("/list")
    public ResultData queryMenuList() {
        List<Tree<String>> menuList = menuService.queryMenuList();
        return ResultData.success(menuList);
    }

    /**
     * 查询当前角色所拥有的所有的菜单以及按钮权限
     * @param
     * @return
     */
    @PostMapping("/role/query")
    public ResultData queryRoleMenuList(@RequestBody Role role) {
        List<Integer> menuIdList = menuService.queryRoleMenuList(role);
        return ResultData.success(menuIdList);
    }
}
